﻿using ZY.EntityFrameWork.WcfSvcLib.Interface;
using ZY.EntityFrameWork.Core.Services;
using ZY.EntityFrameWork.Core.Model.Dto;
using ZY.EntityFrameWork.Core.DBHelper;
using System.Collections.Generic;
using ZY.EntityFrameWork.Core.Model.Entity;
using System.Linq;

namespace ZY.EntityFrameWork.WcfSvcLib.Impl
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的类名“ArvOPService”。
    public class WcfArvOpSvc : BaseArvOpService, IWcfArvOpService
    {
        #region 位置信息
     
        /// <summary>
        /// 判断位置信息是否已经存在
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public bool CheckLocationExists(ArvLocationDto dto)
        {
            return base.CheckLocationExists(dto.MapTo<ArvLocation>());
        }

        public int AddNewLocation(ArvLocationDto dto)
        {
            return base.AddNewLocation(dto.MapTo<ArvLocation>());
        }

        public int AddNewLocations(List<ArvLocationDto> dtos)
        {
            return base.AddNewLocations(dtos.MapTo<List<ArvLocation>>());
        }

        #endregion

        #region 入库相关

        /// <summary>
        /// 查找在库档案
        /// </summary>
        /// <returns></returns>
        new public List<ArchiveInfoDto> GetArvInLib()
        {
            //IQueryble无法映射，可能是因为它在枚举之前是并没有加载数据的原因，其他地方都要换成List或Inumerable
            return base.GetArvInLib().MapTo<List<ArchiveInfoDto>>();
        }

        /// <summary>
        /// 档案入库
        /// </summary>
        /// <param name="arv"></param>
        public int InputToLib(ArchiveInfoDto arv)
        {
            return base.InputToLib(arv.MapTo<ArchiveInfo>());
        }

        /// <summary>
        /// 多条档案同时入库
        /// </summary>
        /// <param name="arvs"></param>
        /// <returns></returns>
        public int InputToLib(List<ArchiveInfoDto> arvs)
        {
            return base.InputToLib(arvs.MapTo<List<ArchiveInfo>>());
        }

        /// <summary>
        /// 单个档案放入柜中(后期看情况第二个参数改成档案盒编号)
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="locDto"></param>
        /// <returns></returns>
        public int InputToCab(ArchiveInfoDto dto, ArvLocationDto locDto)
        {
            ArchiveInfo info = dto.MapTo<ArchiveInfo>();
            ArvLocation arvLocation = locDto.MapTo<ArvLocation>();
            return base.InputToCab(info, arvLocation);
        }

        /// <summary>
        /// 多个档案放入同一位置
        /// </summary>
        /// <param name="arvs"></param>
        public int InputToCab(List<ArchiveInfoDto> arvs, ArvLocationDto locDto)
        {
            List<ArchiveInfo> infos = arvs.MapTo<List<ArchiveInfo>>();
            //指定位置
            ArvLocation arvLocation = locDto.MapTo<ArvLocation>();
            return base.InputToCab(infos, arvLocation);
        }
        #endregion

        #region 借阅相关
        /// <summary>
        /// 查找在柜档案
        /// </summary>
        /// <returns></returns>
        new public List<ArchiveInfoDto> GetArvInCab()
        {
            return base.GetArvInCab().MapTo<List<ArchiveInfoDto>>();
        }

        public int ArvLend(LendInfoDto lendInfo, List<ArchiveInfoDto> arvInfos)
        {
            List<ArchiveInfo> infos = arvInfos.MapTo<List<ArchiveInfo>>();
            LendInfo info = lendInfo.MapTo<LendInfo>();
            return base.ArvLend(info, infos);
        }

        #endregion

        #region 归还相关
        /// <summary>
        /// 查找被借阅的档案
        /// </summary>
        /// <returns></returns>
        new public List<ArchiveInfoDto> GetArvLended()
        {
            return base.GetArvLended().MapTo<List<ArchiveInfoDto>>();
        }

        public int ArvReturn(ReturnInfoDto returnInfo, List<ArchiveInfoDto> arvInfos)
        {
            List<ArchiveInfo> infos = arvInfos.MapTo<List<ArchiveInfo>>();
            ReturnInfo info = returnInfo.MapTo<ReturnInfo>();
            return base.ArvReturn(info, infos);
        }
        #endregion

        #region 出柜相关

        public int ArvOutput(OutCabInfoDto dto, List<ArchiveInfoDto> arvInfos)
        {
            List<ArchiveInfo> infos = arvInfos.MapTo<List<ArchiveInfo>>();
            OutCabInfo outModel = dto.MapTo<OutCabInfo>();

            return base.ArvOutput(outModel, infos);
        }

        #endregion
    }
}
